//对axios进行二次封装
import axios from 'axios'
import nprogress from 'nprogress'
import "nprogress/nprogress.css"
import store from '@/store'
let instance  = axios.create({
    baseURL:"/api",
    timeout:5000

})
instance.interceptors.request.use((config)=>{
   if(store.state.shopcart.userTempId){
        config.headers.userTempId = store.state.shopcart.userTempId
   }
   if(store.state.user.token){
       config.headers.token = store.state.user.token
   }
    nprogress.start();
    return config
}

)
instance.interceptors.response.use((res)=>{
    nprogress.done();
    
    return res.data
   
},(error)=>{
    return Promise.reject(error)
})

//对外暴露二次封装的axios
export default instance;